﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Xeml.Document
{
    public abstract class DynamicValueBase : ValueBase
    {

        private DynamicValueCollection _collection;
        public DynamicValueCollection Collection
        {
            get
            {
                return _collection;
            }
            internal set
            {
                if (value != null)
                {
                    _collection = value;
                }
            }
        }


        protected TimeSpan _timePoint;
        /// <summary>
        /// The time point for a value.
        /// </summary>
        public virtual TimeSpan Time
        {
            get
            {
                //causes site effects -> that why I have removed
                //if (this.Collection != null && this.Collection.Owner is StorySplit)
                //{
                //    return this._timePoint >= (this.Collection.Owner as StorySplit).Time ? _timePoint : (this.Collection.Owner as StorySplit).Time;
                //}
                return this._timePoint;
            }
            set
            {
                if (_timePoint != value)
                {
                    this._timePoint = value;
                    OnPropertyChanged("Time");
                    // OnChanged();
                }
            }
        }


        /// <summary>
        /// The standard constructor.
        /// </summary>
        public DynamicValueBase()
            : base()
        {
            _timePoint = TimeSpan.Zero;
        }


           /// <summary>
        /// The copy constructor.
        /// </summary>
        /// <param name="val">The proptotype for the copy process.</param>
        public DynamicValueBase(DynamicValueBase val)
            : base(val)
        {
            _timePoint = val.Time;            
        }
    }
}
